package com.idemon.ds.controller;

import com.idemon.config.Consts;
import com.idemon.ds.model.Category;
import com.idemon.ds.model.Favor;
import com.idemon.ds.model.Software;
import com.idemon.ds.model.Userinfo;
import com.jfinal.core.Controller;

public class DataController extends Controller {

	public void index(){
		render(Consts.DEFAULT_URL_INDEX);
	}
	
	public void allsoft(){
		renderJson(Category.dao.getAllWithSoft());
	}
	
	public void maxdown(){
		renderJson(Software.dao.getSoft4MaxDown());
	}
	
	public void newdata(){
		renderJson(Software.dao.getSoft4New());
	}
	
	public void isfavor() {
		Object obj = getSessionAttr(Consts.ATTR_KEY_SESSION_USER);
		if (obj != null) {
			int uid = ((Userinfo) obj).getUid();
			int sid = getParaToInt("sid");
			if (Favor.dao.isFavored(uid, sid)) {
				renderJson(1);
				return;
			}
		}
		renderJson(0);
	}

}
